<?php

// Init owncloud

require_once(OC_App::getAppPath('resumes') . "/lib/tag.php");
require_once(OC_App::getAppPath('resumes') . "/lib/helper.php");

$LoginStats = PUtil::checkUserLogin(true);
if ($LoginStats !== true) {
   echo $LoginStats;
   exit();
}

OCP\JSON::callCheck();

$user = PFactory::getMasterUser();
$companyid = $user->id;

$jobid = JRequest::getInt('jobid', 0);
$resumeid = JRequest::getInt('resumeid', 0);

$model = new PResumesModelTag();
$resumeTags = $model->getResumeTags($resumeid, $companyid);

$searchUrl = OCP\Util::linkToRoute('resumes_search');

if(!empty($resumeTags)) {
   foreach($resumeTags as $resumeTag) {
      list($href, $selected) = PResumesHelper::getSearchItemHref($searchUrl, 'keyword', rawurlencode($resumeTag->name));
      $resumeTag->href = $href;
   }
}

$data = array('tags' => $resumeTags, 'admin' => PCompanyHelper::checkJobManagerPermissions($jobid));

OCP\JSON::success(array('data' => $data));